package com.lcy.struct.bTreePlus.disk.server;

import lombok.SneakyThrows;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;
import java.nio.channels.SocketChannel;
import java.nio.charset.StandardCharsets;

/**
 * @author lucongyang
 * @date Created in  13:10
 * @description
 */
public class DatabaseServer {
    @SneakyThrows
    public void socket() {
        ServerSocket serverSocket = new ServerSocket(6033);
        Socket client = null;
        while (true) {
            client = serverSocket.accept();
            InputStreamReader in = new InputStreamReader(client.getInputStream());
            BufferedReader br = new BufferedReader(in);
            String content = "";
            System.out.println(1);
            String s;
            while ((s = br.readLine()) != null && !"".equals(s)) {
                content += s;
            }
            System.out.println("结束：" + content);

            client.getOutputStream().write("success".getBytes(StandardCharsets.UTF_8));
            br.close();
            in.close();
            client.close();
        }
    }
}
